import { Component,OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import {BehalfService} from "../../service/behalf.service";
import { NzMessageService } from 'ng-zorro-antd/message';
import {Behalf} from "../../interface/behalf";

@Component({
  selector: 'app-behalf',
  templateUrl: './behalf.component.html',
  styleUrls: ['./behalf.component.scss']
})

export class BehalfComponent implements OnInit{

  constructor(private route:ActivatedRoute,private buhalfServer:BehalfService,private message: NzMessageService){}
  type:number=1
  user:string=''
  behalfs:Behalf[] = []
  ngOnInit(): void {
    this.getParams()
    this.getBehalfs()
  }
  // 获取路由参数
  getParams():void{
    this.route.params.subscribe(params=>{
      this.type = params['id']
      console.log(this.type);
    })
  }
  // 登陆按钮
  login(name:string):void{
    if(this.buhalfServer.search(name)){
      this.user = name
      this.message.create('success', `登陆成功，欢迎 ${name} 回来`);
    }else{
       this.message.create('error', `该用户名为 ${name} 不存在，请重输`);
    }
  }
  // 获取代办列表
  getBehalfs():void{
    this.buhalfServer.getBehalfs()
      .subscribe(heroes => this.behalfs = heroes);
    console.log(this.behalfs)
  }
 }
